import store from '@/store/index'
const gzt = [
  { label: '离线', value: '0' },
  { label: '在线', value: '1' },
  { label: '未上线', value: '9' },
]
let elctype = [0, 1, 5, 6, 7, 8, 11, 12, 101, 3]
let qcctype = [2, 10, 4, 61, 62]
let cdgctype = [51]
const gtype = [
  { label: '二轮充电桩', value: `gtype in (${elctype.toString()})` },
  { label: '汽车充电桩', value: `gtype in (${qcctype.toString()})` },
  { label: '充电柜', value: `gtype in (${cdgctype.toString()})` },
]
const ctype = [
  { label: '未知', value: '0' },
  { label: 'ID卡', value: '1' },
  { label: 'IC卡', value: '2' },
]
const ntype = [
  { label: '未知', value: '0' },
  { label: '2G', value: '1' },
  { label: '4G', value: '2' },
  { label: 'NB', value: '3' },
  { label: 'wifi', value: '4' },
  { label: '有线', value: '5' },
  { label: '脱机', value: '6' },
]
const xtype = [
  ({ label: '未知', value: '0' },
  { label: '10路充电桩', value: '1' },
  { label: '5路充电桩', value: '2' },
  { label: '20路充电桩', value: '5' },
  { label: '不定路数充电桩', value: '3' },
  { label: '四合一充电桩', value: '4' }),
]
const type = [
  {
    label: '免费',
    value: '0',
  },
  {
    label: '电量计费',
    value: '1',
  },
  {
    label: '固定计费',
    value: '2',
  },
  {
    label: '阶梯计费',
    value: '3',
  },
  {
    label: '起步模式',
    value: '4',
  },
  {
    label: '小时模式',
    value: '5',
  },
  {
    label: '小时阶梯模式',
    value: '6',
  },
  {
    label: '小时退费',
    value: '7',
  },
  {
    label: '阶梯退费',
    value: '8',
  },
  {
    label: '阶梯金额',
    value: '9',
  },
  {
    label: '服务费模式',
    value: '10',
  },
  // {
  //   label: '充电柜租置2',
  //   value: '11',
  // },
]
let gyg = [
  {
    label: '正常',
    value: '0',
  },
  {
    label: '报警',
    value: '1',
  },
  {
    label: '故障',
    value: '2',
  },
  {
    label: '未启用',
    value: '3',
  },
]
let glzt = [
  {
    label: '空闲',
    value: '0',
  },
  {
    label: '被占用',
    value: '1',
  },
  {
    label: '故障',
    value: '2',
  },
]
let b_use = [
  {
    label: '设备不支持扫码充电',
    value: '0',
  },
  {
    label: '正常使用',
    value: '1',
  },
  {
    label: '系统升级中',
    value: '2',
  },
  {
    label: '设备维护中',
    value: '3',
  },
  {
    label: '只支持微信',
    value: '4',
  },
  {
    label: '只支持支付宝',
    value: '5',
  },
  {
    label: '只支持余额支付',
    value: '6',
  },
]
let utype = [
  // { value: '29', label: '配置员' },
  { value: '30', label: '管理员' },
]

export function typeudjfn(data) {
  let r = []
  if (
    ['11', '12', '7', '15'].find((e) => {
      return e == data.utype
    })
  ) {
    r = [
      { value: '0', label: '超级用户' },
      { value: '1', label: '一级用户' },
      { value: '2', label: '二级用户' },
    ]
  }
  if (
    ['0', '3'].find((e) => {
      return e == data.utype
    })
  ) {
    r = [
      { value: '0', label: '超级用户' },
      { value: '1', label: '一级用户' },
      { value: '2', label: '二级用户' },
      { value: '3', label: '三级用户' },
    ]
  }
  return r
}
// "0", "12", "18", "19", "20", "4", "3"
let UPWutypes = ['0', '12', '18', '19', '20', '4', '3']
let b_zf = [
  { value: '0', label: '不支付' },
  { value: '3', label: '支付' },
]
// var zftypeicon = {
//   "": [3, 4, 6, 7, 9, 11, 13, 15, 17, 19, 23],
//   "icon-saoma1": [0, 1, 2, 3, 5, 8, 10, 12, 14, 16, 18, 20, 21, 22],
//
//   "": [26]
// };

let cdtype = [
  { label: '免费', value: '0', icon: 'icon-saoma1' },
  { label: '电量计费', value: '1', icon: 'icon-saoma1' },
  { label: '固定计费', value: '2', icon: 'icon-saoma1' },
  { label: '电量计费刷卡用户', value: '3', icon: 'icon-SKJYJCTJ' },
  { label: '固定计费刷卡用户', value: '4', icon: 'icon-SKJYJCTJ' },
  { label: '阶梯计费', value: '5', icon: 'icon-saoma1' },
  { label: '次卡刷卡', value: '6', icon: 'icon-SKJYJCTJ' },
  { label: '阶梯计费刷卡用户', value: '7', icon: 'icon-SKJYJCTJ' },
  { label: '起步计费', value: '8', icon: 'icon-saoma1' },
  { label: '起步计费刷卡用户', value: '9', icon: 'icon-SKJYJCTJ' },
  { label: '按小时收费', value: '10', icon: 'icon-saoma1' },
  { label: '按小时收费刷卡用户', value: '11', icon: 'icon-SKJYJCTJ' },
  { label: '按小时阶梯收费', value: '12', icon: 'icon-saoma1' },
  { label: '按小时阶梯收费刷卡用户', value: '13', icon: 'icon-SKJYJCTJ' },
  { label: '小时退费模式', value: '14', icon: 'icon-saoma1' },
  { label: '小时退费模式刷卡用户', value: '15', icon: 'icon-SKJYJCTJ' },
  { label: '阶梯退费模式', value: '16', icon: 'icon-saoma1' },
  { label: '阶梯退费模式刷卡用户', value: '17', icon: 'icon-SKJYJCTJ' },
  { label: '阶梯金额模式', value: '18', icon: 'icon-saoma1' },
  { label: '阶梯金额模式刷卡用户', value: '19', icon: 'icon-SKJYJCTJ' },
  { label: '用户购买优惠包月模式', value: '20', icon: 'icon-saoma1' },
  { label: '用户购买优惠包年模式', value: '21', icon: 'icon-saoma1' },
  { label: '服务费计费用户', value: '22', icon: 'icon-saoma1' },
  { label: '服务费计费刷卡', value: '23', icon: 'icon-SKJYJCTJ' },
  { label: '投币用户', value: '24', icon: 'icon-yiyuanqitou' },
  { label: '云闪付', value: '26', icon: 'icon-yunshanfu' },
  { label: '离线模式充电', value: '28', icon: 'icon-saoma1' },
  { label: '充电桩租置模式；', value: '29', icon: 'icon-saoma1' },
  { label: '充电桩租置模式卡支付', value: '30', icon: 'icon-SKJYJCTJ' },
  { label: '汽车桩电量包模式', value: '31', icon: 'icon-saoma1' },
  { label: '未知模式', value: '32', icon: 'icon-saoma1' },
]
let b_askb_dlcallback = async function (data, datas) {
  let chargecar = {}
  if (datas) {
    let gtels = datas.map(function (e) {
      return e.gtel
    })
    gtels = [...new Set([...gtels])]
    let resdata = { gtelsum: gtels.length }
    gtels.forEach(function (e, i) {
      resdata[`gtel${i + 1}`] = e
    })

    let chargecars = await store.dispatch('request/getRequest', {
      url: '/ChargeCarCD',
      data: resdata,
    })
    chargecar = chargecars.find(function (e) {
      return e.gtel == data
    })
    if (!chargecar) {
      return ''
    }
  } else {
    chargecar = await store.dispatch('chargecar/getchargecar', data.gtel)
  }
  if (chargecar.b_ask != 1) {
    return ''
  }
  let json = []
  if (data.gtype == 62) {
    json = [
      { label: '设备编号不匹配', value: '1' },
      {
        label: '枪已在充电',
        value: '2',
      },
      { label: '设备故障', value: '3' },
      { label: '设备离线', value: '4' },
      {
        label: '未插枪',
        value: '5',
      },
    ]
  } else {
    json = [
      { label: '2分钟未检测到充电设备', value: '1' },
      {
        label: '计时结束',
        value: '2',
      },
      { label: '插拔断开', value: '3' },
      { label: '最大充电时长12小时断开', value: '4' },
      {
        label: '功率过大断开',
        value: '5',
      },
      { label: '充满断开', value: '6' },
      { label: '平台结束充电', value: '7' },
      {
        label: '充电口打开失败',
        value: '8',
      },
      { label: '用户自己退款', value: '9' },
      { label: '设备离线', value: '10' },
      { label: '电池电压过高断电', value: '11' },
      {
        label: '电池故障断电',
        value: '12',
      },
    ]
  }
  let r = json.find(function (f) {
    return f.value == data.b_dl
  })
  return r ? r.label : ''
}
let flfn = function (data) {
  if (data.sjtk) {
    return '0.00'
  }
  let GetRfCDnofltype = [3, 4, 6, 7, 9, 11, 13, 15, 17, 19, 23, 27]
  GetRfCDnofltype = GetRfCDnofltype.find((e) => {
    return e == data.type
  })
  if (GetRfCDnofltype) {
    return '0.00'
  }
  let je = data.je
  return je == 0
    ? '0'
    : Math.round((je * 0.6) / 100) == 0
    ? 0.01
    : (Math.round((je * 0.6) / 100) / 100).toFixed(2)
}
let GetRfUserutype = [
  { label: '微信用户', value: '5' },
  { label: '支付宝用户', value: '6' },
  { label: '刷卡用户', value: '7' },
  { label: '次卡用户', value: '8' },
]
let cardtype = [
  { label: '消费卡', value: '0', dw: '元', fl: '100' },
  { label: '次数卡', value: '1', dw: '次' },
  { label: '站点消费卡', value: '2', dw: '元', fl: '100' },
  { label: '月卡(整月)', value: '3', dw: '月' },
  { label: '月卡', value: '4', dw: '月' },
  { label: '时间月卡', value: '5', dw: '小时', fl: '60' },
  { label: '到期卡', value: '6', dw: '次/日' },
]
let cardjecallback = function (data) {
  let type = cardtype.find((e) => {
    return e.value == data.type
  })
  if (type) {
    let r = data.je
    if (type.fl) {
      r = data.je / type.fl
      r = type.fl == 100 ? r.toFixed(2) : r.toFixed(1)
    }
    return r + type.dw
  } else {
    return ''
  }
}
let zfyy = [
  { label: '流量费', value: '0' },
  { label: '电费', value: '1' },
  { label: '收入', value: '2' },
  { label: '站点消费卡', value: '3' },
]
async function GetRfFaultTdcallback(data) {
  let GetRfFaultTd = await store.dispatch('request/getRequest', {
    url: '/GetRfFaultTd',
    data: { gtel: data.gtel },
  })
  let GetRfFaultTddata = GetRfFaultTd.find((e) => {
    return e.td == data.td && e.gtel == data.gtel
  })
  let r = []
  if (GetRfFaultTddata) {
    r.push({
      label: `退款原因`,
      value: 'tkyy',
      defaultValue: '插座故障',
    })
  }
  return r
}
const b_cmzt = [
  { label: '是', value: '1' },
  { label: '否', value: '0' },
]
const GetAlListtype = [
  { label: '短路报警', value: '1' },
  { label: '烟雾报警', value: '2' },
  { label: '充电异常', value: '3' },
  { label: '温度报警', value: '4' },
  { label: '线缆温度报警', value: '5' },
  { label: '继电器故障报警', value: '8' },
  { label: '线缆温度报警', value: '12' },
]
export default {
  GetAlListtype,
  b_cmzt,
  cardjecallback,
  GetRfFaultTdcallback,
  zfyy,
  cardtype,
  GetRfUserutype,
  flfn,
  b_askb_dlcallback,
  b_zf,
  gzt,
  gtype,
  ctype,
  ntype,
  xtype,
  type,
  qcctype,
  gyg,
  glzt,
  b_use,
  utype,
  UPWutypes,
  cdtype,
}
